#! /bin/bash


np=$1;
npstride=$2;
if  [[ $npstride != 1 ]]
then
    corenum[0]=1
    for i in `seq  $npstride $npstride $np`
    do
        corenum[$(($i/$npstride))]=$i;
        #echo ${corenum[$(($i/$npstride))]} $i
    done
else
    for i in `seq  1 $np`
    do
        corenum[$(($i-1))]=$i;
        #echo ${corenum[$(($i/$npstride))]} $i
    done
fi




total=22
a=13;
b=13;
for exe in 2d-jacobi-life-blocking
do

    rm result/$exe-256.txt  
    rm result/$exe-128.txt  
    for index in `seq $a $b`;
    do 
    nx=$((2 ** $index))
    t=$((2 ** ($total - $index)))
    for i in "${corenum[@]}";
    do
        export OMP_NUM_THREADS=$i;../$exe/exe-$exe 8000 8000 2000 256 256 32 >> result/$exe-256.txt  
        export OMP_NUM_THREADS=$i;../$exe/exe-$exe 8000 8000 2000 128 128 32 >> result/$exe-128.txt  
        echo  $i >> result/$exe.cpulist
    done
    done
done


cat result/$exe-256.txt|awk -F "= " '{print $NF}'|paste  result/$exe.cpulist - - - - >  result/$exe.data.txt
cat result/$exe-128.txt|awk -F "= " '{print $NF}'|paste  result/$exe.data.txt - - - -| awk '{printf("%d\t%f\t%f\t%f\t%f\n",$1,($2>$6)?$2:$6,($3>$7)?$3:$7,($4>$8)?$4:$8,($5>$9)?$5:$9) }'> result/$exe.data2.txt


echo -e "np\tscalar\tauto\tour\tour" > result/$exe.data.txt

cat result/$exe.data2.txt|awk -F "= " '{print $NF}'| awk '{print $0}' >>  result/$exe.data.txt
rm  result/$exe.data2.txt
rm result/$exe.cpulist